import Vue from 'vue'
import Vuex from 'vuex'

import user from '@/store/modules/user'
import settings from '@/store/modules/settings'

Vue.use(Vuex)

const store = new Vuex.Store({
  modules: {
    user,
    settings
  },
  strict: true,
  state: {
    count: 100,
    title: '仓库-大标题',
    list: [12, 4, 33, 24, 322, 13, 15, 17, 32, 55]
  },
  getters: {
    filterList (state) {
      return state.list.filter(item => item > 35)
    }
  },
  mutations: {
    setTitle (state, title) {
      state.title = title
    },
    optCount (state, arr) {
      if (arr[0] === '+') {
        state.count += arr[1]
      } else if (arr[0] === '-') {
        state.count -= arr[1]
      } else if (arr[0] === '=') {
        state.count = arr[1]
      } else {
        console.error('无效的操作符')
      }
    }
  },
  actions: {
    changeCountAction (context, num) {
      setTimeout(() => {
        context.commit('optCount', ['=', num])
      }, 3000)
    }
  }

})
export default store
